//
//  CommunityListInfo.m
//  QRMaster
//
//  Created by myApple on 15/12/23.
//  Copyright (c) 2015年 myApple. All rights reserved.
//

#import "CommunityListInfo.h"
#import "OperationDataBaseModel.h"
#import "CommunityListModel.h"

@interface CommunityListInfo()
{
    OperationDataBaseModel * operation;
}

@end

@implementation CommunityListInfo

#pragma mark ----------------插入集群列表信息
-(void)insertCommunityListInfo:(NSString *)communityId withCommunityName:(NSString *)communityName withCommunityAreaCode:(NSString *)areaCode
{
    NSMutableDictionary * communityListDict = [[NSMutableDictionary alloc]init];
    [communityListDict setValue:communityId forKey:@"communityid"];
    [communityListDict setValue:communityName forKey:@"communityname"];
    [communityListDict setValue:areaCode forKey:@"areaCode"];
    operation = [[OperationDataBaseModel alloc]init];
    [operation insertDataTable:@"communityList" withDict:communityListDict];
}


#pragma mark ----------------删除集群列表信息
-(void)deleteCommunityListInfo:(NSString *)communityId
{
    NSString * condition = [NSString stringWithFormat:@"where communityid = %@",communityId];
    operation = [[OperationDataBaseModel alloc]init];
    [operation deleteDataFromTable:@"communityList" withCondition:condition];
}


#pragma mark ------------------查询集群信息
-(void)queryCommunityName:(NSString *)communityId block:(communityDataBlock)communityName
{
    __block NSString * communityNameStr=@"";
    
    NSString * condition = [NSString stringWithFormat:@"where %@=%@",@"communityId",communityId];
    operation = [[OperationDataBaseModel alloc]init];
    [operation queryDataFromTable:@"communityList" withCondition:condition block:^(FMResultSet *set) {
        while ([set next]) {
            communityNameStr = [set objectForColumnName:@"communityname"];
        }
        if (communityName) {
            communityName(communityNameStr);
        }
    }];
}


#pragma mark ----------------查询集群列表的所有信息
-(void)queryAllCommunityInfoBlock:(void (^)(NSMutableArray *))block
{
    operation = [[OperationDataBaseModel alloc]init];
    __block NSMutableArray * communityInfoArray = [[NSMutableArray alloc]init];
    [operation queryDataFromTable:@"communityList" withCondition:@"where 1=1" block:^(FMResultSet *set) {
        while ([set next]) {
            CommunityListModel * model = [[CommunityListModel alloc]init];
            model.communityId = [set objectForColumnName:@"communityid"];
            model.communityName = [set objectForColumnName:@"communityname"];
            model.areaCodeString = [set objectForColumnName:@"areaCode"];
            [communityInfoArray addObject:model];
        }
        if (block) {
            block(communityInfoArray);
        }
    }];
}


@end
